package com.broadengate.dao.impl;

import java.util.ArrayList;
import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.broadengate.dao.OperaHistoryDao;
import com.broadengate.model.*;

/******
 * 提供查询操作记录时与数据库的交互方法
 * 方法主要有listAllOperation()查找所有操作记录；DepositList()查找存款操作记录;WithdrawList()查找取款记录;TrasferList()查找转账记录;
 */
public class OperaHistoryDaoImpl extends HibernateDaoSupport implements OperaHistoryDao {
	@SuppressWarnings("unchecked")
	public List listAllOperation(String CardNO) {
		List<List> list=new ArrayList<List>();
		List<Deposit> listDeposit=new ArrayList();
		List<Withdraw> listWithdraw=new ArrayList();
		List<Transfer> listTransfer=new ArrayList();
		//Hibernate不需要通过使用getXXX（）来获取属性
		listDeposit=getHibernateTemplate().find("from Deposit deposit where deposit.card.cardNo='"+CardNO+"' order by deposit.time asc");
		listWithdraw=getHibernateTemplate().find("from Withdraw withdraw where withdraw.card.cardNo='"+CardNO+"' order by withdraw.time asc");
		listTransfer=getHibernateTemplate().find("from Transfer transfer where transfer.cardBySourceCardId.cardNo='"+CardNO+"' or transfer.cardByDestinedCardId.cardNO='"+CardNO+"' order by transfer.time asc");
		list.add(0,listDeposit);
		list.add(1,listWithdraw);
		list.add(2,listTransfer);
		return list;
	}
	
	@SuppressWarnings("unchecked")
	public List DepositList(String CardNO) {		
		List<Deposit> listDeposit=new ArrayList();
		
		listDeposit=getHibernateTemplate().find("from Deposit deposit where deposit.card.cardNo='"+CardNO+"' order by deposit.time asc");
		return listDeposit;
	}
	
	@SuppressWarnings("unchecked")
	public List WithdrawList(String CardNO) {	
		List<Withdraw> listWithdraw=new ArrayList();
		listWithdraw=getHibernateTemplate().find("from Withdraw withdraw where withdraw.card.cardNo='"+CardNO+"' order by withdraw.time asc");
		return listWithdraw;
	}
	
	@SuppressWarnings("unchecked")
	public List TrasferList(String CardNO) {
		List<Transfer> listTransfer=new ArrayList();
		listTransfer=getHibernateTemplate().find("from Transfer transfer where transfer.cardBySourceCardId.cardNo='"+CardNO+"' or transfer.cardByDestinedCardId.cardNo='"+CardNO+"' order by transfer.time asc");		
		return listTransfer;
	}
}
